package com.hqd.jjvm.classformat.attributeinfo;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
public class RuntimeVisibleParameterAnnotations extends ParameterAnnotationAttributeInfo {
	private Integer numParameters;
	List<RuntimeInvisibleParameterAnnotations.ParameterAnnotations> parameterAnnotationList;

	public RuntimeVisibleParameterAnnotations(Integer attributeNameIndex, Integer attributeLength, Integer numParameters) {
		super(attributeNameIndex, attributeLength);
		this.numParameters = numParameters;
	}

	@Getter
	static class ParameterAnnotations {
		private Integer numAnnotations;
		private List<ElementValuePair.Annotation> annotationList;

		public ParameterAnnotations(Integer numAnnotations, List<ElementValuePair.Annotation> annotationList) {
			this.numAnnotations = numAnnotations;
			this.annotationList = annotationList;
		}
	}

	@Override
	protected RuntimeVisibleParameterAnnotations newAttributeInfo(Integer attributeNameIndex, Integer attributeLength, ClassFile classFile) {
		this.numParameters = HexStrTransformUtil.parseHexToInt(classFile.readU1());
		this.parameterAnnotationList = parseParameterAnnotations(classFile, numParameters);
		return this;
	}
}
